package com.qdc.datacenters.controller;

import com.github.pagehelper.PageInfo;
import com.qdc.datacenters.annotation.Log;
import com.qdc.datacenters.domain.ResponseResult;
import com.qdc.datacenters.domain.query.chatmsg.ChatMsgListQuery;
import com.qdc.datacenters.domain.query.chatmsg.ChatMsgQuery;
import com.qdc.datacenters.domain.vo.chatmsg.*;
import com.qdc.datacenters.enums.BusinessTypeEnum;
import com.qdc.datacenters.service.IChatContactMsgService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author danmo
 * @date 2024-03-05 16:44
 **/
@Tag(name = "会话存档")
@RestController
@RequestMapping("/chatMsg")
public class ChatContactMsgController extends BaseController{

    @Autowired
    private IChatContactMsgService iChatContactMsgService;

    @Log(title = "获取员工列表",businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('chatMsg:user:list')")
    @Operation(summary = "获取员工列表", method = "POST")
    @PostMapping("/user/list")
    public ResponseResult<PageInfo<ChatMsgUserListVo>> getUserMsgList(@RequestBody ChatMsgListQuery query){
        startPage(query.getPageIndex(), query.getPageSize(),query.getSortField(),query.getSort());
        List<ChatMsgUserListVo> userMsgList = iChatContactMsgService.getUserMsgList(query);
        PageInfo<ChatMsgUserListVo> pageInfo = new PageInfo<>(userMsgList);
        return ResponseResult.success(pageInfo) ;
    }

    @Log(title = "获取客户列表",businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('chatMsg:customer:list')")
    @Operation(summary = "获取客户列表", method = "POST")
    @PostMapping("/customer/list")
    public ResponseResult<PageInfo<ChatMsgCustomerListVo>> getCustomerMsgList(@RequestBody ChatMsgListQuery query){
        startPage(query.getPageIndex(), query.getPageSize(),query.getSortField(),query.getSort());
        List<ChatMsgCustomerListVo> customerMsgList = iChatContactMsgService.getCustomerMsgList(query);
        PageInfo<ChatMsgCustomerListVo> pageInfo = new PageInfo<>(customerMsgList);
        return ResponseResult.success(pageInfo) ;
    }

    @Log(title = "获取群聊列表",businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('chatMsg:room:list')")
    @Operation(summary = "获取群聊列表", method = "POST")
    @PostMapping("/room/list")
    public ResponseResult<PageInfo<ChatMsgRoomListVo>> getRoomMsgList(@RequestBody ChatMsgListQuery query){
        startPage(query.getPageIndex(), query.getPageSize(),query.getSortField(),query.getSort());
        List<ChatMsgRoomListVo> roomMsgList = iChatContactMsgService.getRoomMsgList(query);
        PageInfo<ChatMsgRoomListVo> pageInfo = new PageInfo<>(roomMsgList);
        return ResponseResult.success(pageInfo) ;
    }

    @Log(title = "根据员工获取外部好友列表",businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('chatMsg:external:customer:list')")
    @Operation(summary = "根据员工获取外部好友列表", method = "POST")
    @PostMapping("/external/customer/list")
    public ResponseResult<PageInfo<ChatMsgExCustomerVo>> getExternalCustomerList(@RequestBody ChatMsgListQuery query){
        startPage(query.getPageIndex(), query.getPageSize(),query.getSortField(),query.getSort());
        List<ChatMsgExCustomerVo> externalCustomerList = iChatContactMsgService.getExternalCustomerList(query);
        PageInfo<ChatMsgExCustomerVo> pageInfo = new PageInfo<>(externalCustomerList);
        return ResponseResult.success(pageInfo) ;
    }

    @Log(title = "根据员工获取内部好友列表",businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('chatMsg:internal:customer:list')")
    @Operation(summary = "根据员工获取内部好友列表", method = "POST")
    @PostMapping("/internal/customer/list")
    public ResponseResult<PageInfo<ChatMsgInCustomerVo>> getInternalCustomerList(@RequestBody ChatMsgListQuery query){
        startPage(query.getPageIndex(), query.getPageSize(),query.getSortField(),query.getSort());
        List<ChatMsgInCustomerVo> externalCustomerList = iChatContactMsgService.getInternalCustomerList(query);
        PageInfo<ChatMsgInCustomerVo> pageInfo = new PageInfo<>(externalCustomerList);
        return ResponseResult.success(pageInfo) ;
    }

    @Log(title = "根据员工获取外部群列表",businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('chatMsg:external:group:list')")
    @Operation(summary = "根据员工获取外部群列表", method = "POST")
    @PostMapping("/external/group/list")
    public ResponseResult<PageInfo<ChatMsgGroupVo>> getExternalGroupList(@RequestBody ChatMsgListQuery query){
        startPage(query.getPageIndex(), query.getPageSize(),query.getSortField(),query.getSort());
        List<ChatMsgGroupVo> externalCustomerList = iChatContactMsgService.getExternalGroupList(query);
        PageInfo<ChatMsgGroupVo> pageInfo = new PageInfo<>(externalCustomerList);
        return ResponseResult.success(pageInfo) ;
    }


    @Log(title = "根据员工获取内部群列表",businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('chatMsg:internal:group:list')")
    @Operation(summary = "根据员工获取内部群列表", method = "POST")
    @PostMapping("/internal/group/list")
    public ResponseResult<PageInfo<ChatMsgGroupVo>> getInternalGroupList(@RequestBody ChatMsgListQuery query){
        startPage(query.getPageIndex(), query.getPageSize(),query.getSortField(),query.getSort());
        List<ChatMsgGroupVo> externalCustomerList = iChatContactMsgService.getInternalGroupList(query);
        PageInfo<ChatMsgGroupVo> pageInfo = new PageInfo<>(externalCustomerList);
        return ResponseResult.success(pageInfo) ;
    }

    @Log(title = "根据客户获取员工列表",businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('chatMsg:customer:user:list')")
    @Operation(summary = "根据客户获取员工列表", method = "POST")
    @PostMapping("/customer/user/list")
    public ResponseResult<PageInfo<ChatMsgCustomerUserVo>> getCustomerUserList(@RequestBody ChatMsgListQuery query){
        startPage(query.getPageIndex(), query.getPageSize(),query.getSortField(),query.getSort());
        List<ChatMsgCustomerUserVo> externalCustomerList = iChatContactMsgService.getCustomerUserList(query);
        PageInfo<ChatMsgCustomerUserVo> pageInfo = new PageInfo<>(externalCustomerList);
        return ResponseResult.success(pageInfo) ;
    }


    @Log(title = "获取会话内容列表",businessType = BusinessTypeEnum.SELECT)
    @PreAuthorize("@authz.hasPerm('chatMsg:msg:list')")
    @Operation(summary = "获取会话内容列表", method = "POST")
    @PostMapping("/msg/list")
    public ResponseResult<PageInfo<ChatContactMsgVo>> getChatMsgList(@RequestBody ChatMsgQuery query){
        List<ChatContactMsgVo> externalCustomerList = iChatContactMsgService.getChatMsgList(query);
        PageInfo<ChatContactMsgVo> pageInfo = new PageInfo<>(externalCustomerList);
        return ResponseResult.success(pageInfo) ;
    }
}
